<?php
class Solution {
    // O(logN)
    /**
     * @param Integer[] $nums
     * @param Integer $target
     * @return Integer
     */
    function search($nums, $target)
    {
        $right = count($nums) - 1 ;
        $left = 0;
        while ($left <= $right) {
            $pivot = intval($left + ($right - $left) / 2);
            if ($nums[$pivot] == $target) {
                return $pivot;
            }
            if ($nums[$pivot] > $target) {
                $right = $pivot - 1;
            } else  {
                $left = $pivot + 1;
            }
        }
        return -1;
    }
}